package com.kiliter.handler;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * @ClassName zhangjl
 * @date 2021/6/2 9:33
 * @Version 1.0
 */
@Aspect
@Component
@Order(2)
public class KiliterHandler {

   @Pointcut("@annotation(com.kiliter.annotations.Kiliter)")
    public void pointCut(){ }

    @Before("pointCut()")
    public void preHandler(){
        System.out.println("前置通知");
    }

    @After("pointCut()")
    public void DemoAop(){
        System.out.println("后置通知");
    }

    @Around("pointCut()")
    public Object AroundHandler(ProceedingJoinPoint joinPoint) {
        Object proceed=null;
        try {
            System.out.println("环绕前");
             proceed = joinPoint.proceed();
            R r = (R) proceed;
            Page page=(Page)r.getData();
            System.out.println(page.getRecords());
            System.out.println("环绕后");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return proceed;
    }
}
